package com.le.tester.leetcode;

/**
 * 描述：最小好进制
 */
public class SmallestGoodBase {
    public String smallestGoodBase(String n) {
        long aLong = Long.parseLong(n);
        //返回最大值，log取对数
        int mMax = (int) (Math.floor(Math.log(aLong)) / Math.log(2));
        for (int m = mMax; m > 1; m--) {
            int k = (int) Math.pow(aLong, 1.0 / m);
            long mul = 1;
            long sum = 1;
            for (int i = 0; i < m; i++) {
                mul *= k;
                sum += mul;

            }
            if (sum == aLong) {
                return Integer.toString(k);
            }
        }
        return Long.toString(aLong - 1);
    }
}
